﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace WindowsGame1
{
    public static class Common
    {
        // This class is used for common enums, constants, etc...

        public enum Difficulty
        {
            GodMode = 0,
            Easy = 1,
            Medium = 2,
            Hard = 3,
            Insane = 4
        }

        public enum Quadrant
        {
            I,
            II,
            III,
            IV
        }

        // Gets the number of seconds since "gameTime" was last used
        public static float ElapsedSeconds(GameTime gameTime)
        {
            return (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        public static Quadrant GetVectorQuadrant(Vector2 vector)
        {
            if (vector.X >= 0 && vector.Y >= 0)
                return Quadrant.I;
            if (vector.X < 0 && vector.Y >= 0)
                return Quadrant.II;
            if (vector.X < 0 && vector.Y < 0)
                return Quadrant.III;
            if (vector.X >= 0 && vector.Y < 0)
                return Quadrant.IV;
            else
                return Quadrant.I;
        }

        /// <summary>
        /// Gets the angle of the given vector from the positive X-axis. It only returns positive values.
        /// </summary>
        /// <param name="vector">2-dimentional vector</param>
        public static float GetVectorAngle(Vector2 vector)
        {
            var quadrant = GetVectorQuadrant(vector);
            if (quadrant == Quadrant.II || quadrant == Quadrant.III)
                return NormalizeAngle(Math.PI + Math.Atan(vector.Y / vector.X));
            else
                return NormalizeAngle(Math.Atan(vector.Y / vector.X));
        }

        public static float NormalizeAngle(float angle)
        {
            if (angle < 0)
                return (2 * (float)Math.PI) - Math.Abs(angle % (2 * (float)Math.PI));
            else
                return angle % (2 * (float)Math.PI);
        }
        public static float NormalizeAngle(int angle) { return NormalizeAngle((float)angle); }
        public static float NormalizeAngle(double angle) { return NormalizeAngle((float)angle); }
        public static float NormalizeAngle(decimal angle) { return NormalizeAngle((float)angle); }

        public static Vector2 VectorFromAngle(float angle, float length = 1.0f)
        {
            return new Vector2((float)(length * Math.Cos(angle)), (float)(length * Math.Sin(angle)));
        }


    }
}
